package cn.com.connected.base.params;

import cn.com.connected.base.exception.BusinessException;
import cn.com.connected.base.exception.ErrorCode;
import lombok.Data;

import java.io.Serializable;

/**
 * 作者:   邵明生
 * 时间:   2018/11/6 9:32
 * 描述:
 */
@Data
public class JsonResult<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private String msg = null;

    private String code = null;

    private T data;

    public JsonResult() {
        super();
    }

    public JsonResult(T data) {
        super();
        this.data = data;
        this.code = ErrorCode.SYSTEM_SUCCESS.getCode();
        this.msg = ErrorCode.SYSTEM_SUCCESS.getMsg();
    }

    public JsonResult(T data, ErrorCode code) {
        this.data = data;
        this.code = code.getCode();
        this.msg = code.getMsg();
    }

    public JsonResult(ErrorCode code) {
        this.code = code.getCode();
        this.msg = code.getMsg();
    }


    public JsonResult(T data, String resCode, String resMsg) {
        this.data = data;
        this.code = resCode;
        this.msg = resMsg;
    }


    public JsonResult(BusinessException e) {
        super();
        this.msg = e.getMsg();
        this.code = e.getCode() ;
    }
}
